package com.typhoon.rpc.registry.db;

import java.util.Calendar;
import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcTemplate;

import com.typhoon.rpc.registry.ServiceRegistry;
import com.typhoon.rpc.registry.db.util.DataSourceUtils;

public class DBServiceRegistry implements ServiceRegistry {
	
	private static final Logger LOGGER = LoggerFactory.getLogger(DBServiceRegistry.class);

	private JdbcTemplate jdbcTempalte = DataSourceUtils.getJdbcTemplate();

	
	@Override
	public void register(String serviceName, String serviceAddress) {
		this.doRegisterServie(serviceName,serviceAddress);
	}


	/**
	 * 注册服务
	 * 
	 * @param serviceName
	 * @param serviceAddress
	 */
	private void doRegisterServie(String serviceName, String serviceAddress) {
		StringBuilder sql = new StringBuilder();
		sql.append("	insert	");
		sql.append("		into	");
		sql.append("	ApiNode		");
		sql.append("	values(null,?,?,now(),now())	");
		this.jdbcTempalte.update(sql.toString(), serviceName,serviceAddress);
	}

}
